<template>
	<view class="page-content">
		<m-loading :show="listLoad" :emptyShow="list.data.length <= 0"></m-loading>
		<m-tasks :list="list.data" v-if="!listLoad"></m-tasks>
		<uni-load-more :status="status" :content-text="contentText" v-if="showLoading"></uni-load-more>
		<!-- 侧边小工具 -->
		<side-tools :scrollTop="scrollTop"></side-tools>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	export default {
		data() {
			return {
				listLoad:true,
				status:"loading",
				scrollTop:0,
				showLoading:false,
			}
		},
		computed: mapState({
			userInfo: state => state.user.userInfo,
			configInfo: state => state.config.configInfo,
			list: state => state.task.collectList,
			param:state => state.task.collectParam,
			contentText: state => state.content.contentText,
		}),
		
		onLoad(){
			// if(this.$wechat.isWechat()) this.$util.navTitle()
		},
		
		onReady(){
			if(this.$wechat.isWechat()) this.$util.navTitle()
		},
		
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		
		/* 页面显示 */
		async onShow(){
			this.getList()
		},
		
		/* 页面隐藏 */
		onHide(){

		},
		
		async onPullDownRefresh(){
			await this.getList(1);
			this.$util.showToast(this.$t('app.renovate.success'),function(){
				uni.stopPullDownRefresh();
			});
		},
		
		async onReachBottom(){
			if (this.list.current_page >= this.list.last_page || this.ListLoad){
				this.status="nomore";
				return
			};
			this.status = "loading";
			this.showLoading = true;
			this.getList(this.param.page + 1);		
		},
		
		methods: {
			...mapActions(['getMyCollectList']),
			...mapMutations(['updateTaskState']),
			async getList(page = 0){
				if (page) {
					let param = uni.$u.deepClone(this.param)
					param.page = page
					this.updateTaskState({
						key: 'collectParam',
						val: param
					})
					console.log(param)
				}
				await this.getMyCollectList(this.param)
				this.listLoad = false
			},
		}
	}
</script>

<style>
	page{
		background-color: var(--theme-page-bg);
	}
</style>